#!/usr/bin/env python
# -*- coding: utf-8
# srt-split.py: split srt files containing Chinese and English

import sys, codecs, os

encoding = "utf-8"

def output(fp, line):
    fp.write(line.encode(encoding))

def is_removable_punct(x):
    # Punct & Radicals
    if x == u"，" or x == u"。" or x == u"；":
        return 1
    return 0

if len(sys.argv) < 2:
    print "usage: %s <file.srt>" % sys.argv[0]
    sys.exit(1)

srt_path = sys.argv[1]
out_file = sys.stdout

if os.path.isfile(srt_path) != True:
    print "File %s does not exist." % srt_path
    sys.exit(1)

srt_file = codecs.open(srt_path, encoding='utf-8')

for line in srt_file:
    if len(line) >= 2 and is_removable_punct(line[-2]):
        output(out_file, line[:-2] + u"\n")
    else:
        output(out_file, line)

out_file.close()

